#import <Foundation/Foundation.h>
#import <sqlite3.h>

#import "FWApplication.h"

#define FWDatabase sqlite3


@protocol FWDBAccessDelegate <NSObject>

- (NSObject*)objectForSQLRecord:(sqlite3_stmt*)sqlStatement withId:(NSInteger)sqlid context:(NSObject*)context application:(FWApplication*)application;

@end


FWDatabase* FWDBConnectDatabase(NSString* dbpath, FWApplication* application);
void FWDBDisconnectDatabase(FWDatabase* database);

NSArray* FWDBGetRecordsFromConnection(NSString* sql, NSInteger sqlid, NSObject* context, FWDatabase* database, FWApplication* application, id<FWDBAccessDelegate> delegate);
NSArray* FWDBGetSortedRecordsFromConnection(NSString* sql, NSInteger sqlid, NSObject* context, FWDatabase* database, FWApplication* application, id<FWDBAccessDelegate> delegate, NSInteger (*compare)(id, id, void *));

NSArray* FWDBGetRecords(NSString* sql, NSInteger sqlid, NSObject* context, NSString* dbpath, FWApplication* application, id<FWDBAccessDelegate> delegate);
NSArray* FWDBGetSortedRecords(NSString* sql, NSInteger sqlid, NSObject* context, NSString* dbpath, FWApplication* application, id<FWDBAccessDelegate> delegate, NSInteger (*compare)(id, id, void *));
